#include "AndroidVideoCapture.h"
#include "VideoCapture.h"

namespace simple_renderer{

const char* JAVA_VideoCapture = "com/vonchenchen/renderer/VideoCapture";

AndroidVideoCapture::AndroidVideoCapture(){


}

AndroidVideoCapture::~AndroidVideoCapture(){

}

int AndroidVideoCapture::AllocCapture(){

    JNIEnv* env = AttachCurrentThreadIfNeeded();
    jclass cls = env->FindClass(JAVA_VideoCapture);
    jmethodID mid_alloc = env->GetMethodID(cls, "allocate", "()I");
    int ret = env->CallIntMethod(_video_capture->operator*(), mid_alloc);

    return ret;
}

int AndroidVideoCapture::DeallocCapture(){

    JNIEnv* env = AttachCurrentThreadIfNeeded();
    jclass cls = env->FindClass(JAVA_VideoCapture);
    jmethodID mid_dealloc = env->GetMethodID(cls, "deallocate", "()V");
    env->CallVoidMethod(_video_capture->operator*(), mid_dealloc);

    return 0;
}

int AndroidVideoCapture::StartCapture(){

    JNIEnv* env = AttachCurrentThreadIfNeeded();
    jclass cls = env->FindClass(JAVA_VideoCapture);
    jmethodID mid_start_capture = env->GetMethodID(cls, "startCapture", "(III)I");
    int ret = env->CallIntMethod(_video_capture->operator*(), mid_start_capture, 640, 480, 15);

    return ret;
}

int AndroidVideoCapture::StopCapture(){

    JNIEnv* env = AttachCurrentThreadIfNeeded();
    jclass cls = env->FindClass(JAVA_VideoCapture);
    jmethodID mid_stop_capture = env->GetMethodID(cls, "stopCapture", "()I");
    int ret = env->CallIntMethod(_video_capture->operator*(), mid_stop_capture);

    return ret;
}

}